import java.net.InetAddress;
import java.net.InetSocketAddress;

import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TNonblockingServerTransport;

import thriftGenerated.myService;


/**
 * Created by dengpan on 2016/12/3.
 */
public class HelloTNoblockingServerDemo {
    public void startServer() {
        try {

            //指定地址
            InetAddress addr = InetAddress.getByName("0.0.0.0");
            InetSocketAddress socketAddress = new InetSocketAddress(addr, 1234);
            TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(socketAddress);

            myService.Processor processor = new myService.Processor(new MyServiceImpl());
            TServer server = new TNonblockingServer(new TNonblockingServer.Args(serverTransport).
                    processor(processor));
            System.out.println("Starting server on port 1234 ...");
            server.serve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        System.out.println("start server....");
        HelloTNoblockingServerDemo server = new HelloTNoblockingServerDemo();
        server.startServer();
    }
}
